package myapps.ttclient.connection;

import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class ConnectionList_Wifi extends ConnectionList
{
	public ConnectionList_Wifi(SharedPreferences preferences)
	{
		super(preferences);
	}
	
	@Override
	public void load()
	{
		this.connections.clear();
		
		int count = this.preferences.getInt("connection_count_wifi", 0);
		
		for (int i = 0; i < count; i++)
		{
			Connection connection = Connection_Wifi.load(this.preferences, i);
			
			this.connections.add(connection);
		}
		
		usedPosition = this.preferences.getInt("connection_used_posistion_wifi", -1);
		
		/*
		if(count <= 0)
		{
			Connection_Wifi c = new Connection_Wifi();
			c.setName("cn.1.200");
			c.setHost("192.168.1.200");
			c.setPort(44472);
			
			this.connections.add(c);
			
			Connection_Wifi c1 = new Connection_Wifi();
			c1.setName("cn.8.1");
			c1.setHost("192.168.8.1");
			c1.setPort(44472);
			
			this.connections.add(c1);
			
			Connection_Wifi c2 = new Connection_Wifi();
			c2.setName("cn.1.201");
			c2.setHost("192.168.1.201");
			c2.setPort(44472);
			
			this.connections.add(c2);
		}*/
	}
	
	@Override
	public void save()
	{
		Editor editor = this.preferences.edit();
		
		int count = this.connections.size();
		editor.putInt("connection_count_wifi", count);
		
		for (int i = 0; i < count; i++)
		{
			this.connections.get(i).save(editor, i);
		}
		
		editor.putInt("connection_used_posistion_wifi", usedPosition);
		
		editor.commit();
	}
	
//	public Connection add()
//	{
//		Connection connection = new Connection_Wifi();
//		
//		this.connections.add(connection);
//		
//		return connection;
//	}
}
